package com.lz.football.module.goldpalace.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.GoldPalaceEvent;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.lz.football.module.base.IComponent;
	
	import common.item.ComGoodsItem;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;
	import lz.controls.LItem;
	import lz.controls.managers.TipsManager;

	/**
	 * 奖励条目 
	 * @author lake
	 * 
	 */	
	public class AwardItem extends LItem implements IComponent
	{
		/**
		 *道具容器 
		 */		
		private var container 		:Sprite;
		/**
		 *时间 
		 */		
		private var txtDate 		:TextField;
		/**
		 *选择mc 
		 */		
		private var selectMc		:MovieClip;
		
		public function AwardItem()
		{
			super();
		}
		/**
		 *选择 or 不选择 
		 * 
		 */		
		override public function select():void
		{
			if(selectMc)
			{
				selectMc.visible = true;
			}
		}
		override public function unSelect():void
		{
			if(selectMc)
			{
				selectMc.visible = false;
			}
		}
		/**
		 * 设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
			var goodsVo :GoodsVo = data.goods;
			if(goodsVo)
			{
				var comItem :ComGoodsItem = new ComGoodsItem();
				comItem.initUI();
				comItem.data = goodsVo;
				DisplayObjectUtil.removeAllChildren(container);
				container.addChild(comItem);
			}
			txtDate.text = data.tstr;
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.football.goldpalace.awardItemSkin");
			this.addChild(_symbolSkin);
			container = _symbolSkin.container;
			txtDate = _symbolSkin.txtDate;
			txtDate.text = "";
			selectMc = _symbolSkin.selectMc;
			selectMc.visible = false;
			addEvtListener();
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,clickH);
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		protected function onOverHandler(e :MouseEvent):void
		{
			if(_data == null || this.alpha == 1)return;
			var info :String = "需要点亮"+_data.index+"个球星";
			TipsManager.show(TipsConst.BASETIPS,{tip:info},15,15,true,true);
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		protected function onOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 *点击 
		 * @param e
		 * 
		 */		
		private function clickH(e :MouseEvent):void
		{
			if(selectMc.visible || this.alpha < 1)
			{
				return;
			}
			var info :String = "激活该奖励会使当前的冷却时间归零，确定激活?";
			Alert.show(info,"",Alert.YES | Alert.NO,GlobalDef.AlertContainer,awardAlertH);
		}
		/**
		 *激活确认 
		 * @param type
		 * 
		 */		
		private function awardAlertH(type :int):void
		{
			if(type == Alert.YES)
			{
				this.dispatchEvent(new GoldPalaceEvent(GoldPalaceEvent.Change_Award,{pos:_data.index},true));
			}
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,clickH);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
		}
	}
}